This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
There are many ways to make graphics in R.
Nice overviews: http://www.datavis.ca/courses/RGraphics/R-Graphics1.pdf https://smithcollege-sds.github.io/136/static/IntroToR_slides.html
hist(rnorm(1000))
A ggplot2 template - Make any plot by filling in the parameters of this template
ggplot(data = ) +
Like this:
ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy))
This would like:
library(ggplot2)
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
ggplot(mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
geom_smooth(mapping = aes(x = displ, y = hwy))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut), stat = "count")
You can also embed plots, for example:
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(p)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
n <- ggplot(mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
geom_smooth(mapping = aes(x = displ, y = hwy))
ggplotly(n)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'